package com.movecar.ui;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextPaint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.movecar.R;
import com.movecar.adapter.GroupDiscussListAdapter;
import com.movecar.adapter.ImagePagerAdapter;
import com.movecar.dialog.CustomDialog;
import com.movecar.listview.MyListView;
import com.movecar.model.CloudBeansBean;
import com.movecar.model.Comments;
import com.movecar.model.GetGroupBean;
import com.movecar.model.GroupBean;
import com.movecar.model.GroupJoinBean;
import com.movecar.model.GroupShareBean;
import com.movecar.model.Pictures;
import com.movecar.utils.Alert;
import com.movecar.utils.AppConfig;
import com.movecar.utils.ConfigCacheUtil;
import com.movecar.utils.DataStore;
import com.movecar.utils.HttpPostRequestAsyncTask;
import com.movecar.utils.ListUtils;
import com.movecar.utils.PopupWindowAnimation;
import com.movecar.utils.RequestResultCallback;
import com.movecar.widget.CustomProgressDialog;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 活动详情
 * 
 * @author Zhao.JQ
 * 
 */
public class GroupDetailActivity extends Activity implements OnClickListener {

	private TextView group_name, group_time, group_address, group_phone, goin_group_name, group_describe, group_rules,
			group_theme;
	private AutoScrollViewPager group_img;
	private ImageView club_img;
	private ImageLoader imageLoader = null;
	private String messageId = "";
	private Button btn_joined_num, message_board, invite_button, make_an_appointment, btn_joined, btn_cancle_joined,
			has_make_an_appointment, check_all;
	private GetGroupBean getGroupBean = null;
	private GroupJoinBean mGroupJoinBean = null;
	private CloudBeansBean mCloudBeansBean = null;
	private GroupShareBean mGroupShareBean = null;
	private LinearLayout goin_group, main_linear;
	private ScrollView mScrollView;
	private CustomProgressDialog progressDialog = null;
	private int position = 1;
	private ArrayList<Comments> mDataList = new ArrayList<Comments>();
	private MyListView mMyListView;
	private int joinednum;
	private RelativeLayout message_title;
	private List<Pictures> pictureList;
	private Button btn_other_joined, invite_button_unclick;
	private int GOPAYMENT = 100;
	private String coin = "0";
	private String rmb = "0";
	private String payCode = "";
	private View mainView;
	private LayoutInflater layoutInflater;

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);mainView = layoutInflater.inflate(R.layout.group_detail, null);
		setContentView(mainView);
		initView();
	}

	private void initView() {
		imageLoader = ImageLoader.getInstance();
		// imageLoader.init(Constants.imageLoaderConfiguration(this));
		messageId = getIntent().getStringExtra("messageId");
		position = getIntent().getIntExtra("position", 1);
		btn_joined = (Button) findViewById(R.id.btn_joined);
		btn_cancle_joined = (Button) findViewById(R.id.btn_cancle_joined);
		btn_other_joined = (Button) findViewById(R.id.btn_other_joined);
		invite_button_unclick = (Button) findViewById(R.id.invite_button_unclick);
		btn_joined_num = (Button) findViewById(R.id.btn_joined_num);
		btn_joined_num.setOnClickListener(this);
		message_board = (Button) findViewById(R.id.message_board);
		message_board.setOnClickListener(this);
		check_all = (Button) findViewById(R.id.check_all);
		check_all.setOnClickListener(this);
		Button back = (Button) findViewById(R.id.btn_left);
		back.setVisibility(View.VISIBLE);
		back.setOnClickListener(this);
		Button share = (Button) findViewById(R.id.btn_right);
		share.setBackgroundResource(R.drawable.btn_group_share);
		share.setVisibility(View.VISIBLE);
		share.setOnClickListener(this);
		message_title = (RelativeLayout) findViewById(R.id.message_title);
		TextView title = (TextView) findViewById(R.id.title);
		title.setText("详情");
		mScrollView = (ScrollView) findViewById(R.id.mScrollView);
		goin_group = (LinearLayout) findViewById(R.id.goin_group);
		goin_group.setOnClickListener(this);
		group_name = (TextView) findViewById(R.id.group_name);
		group_time = (TextView) findViewById(R.id.group_time);
		group_address = (TextView) findViewById(R.id.group_address);
		group_phone = (TextView) findViewById(R.id.group_phone);
		goin_group_name = (TextView) findViewById(R.id.goin_group_name);
		group_describe = (TextView) findViewById(R.id.group_describe);
		group_theme = (TextView) findViewById(R.id.group_theme);
		group_rules = (TextView) findViewById(R.id.group_rules);
		group_img = (AutoScrollViewPager) findViewById(R.id.group_img);
		club_img = (ImageView) findViewById(R.id.club_img);
		mMyListView = (MyListView) findViewById(R.id.mListView);
		main_linear = (LinearLayout) findViewById(R.id.main_linear);
		// 添加拨打电话监听
		group_phone.setOnClickListener(this);
		invite_button = (Button) findViewById(R.id.invite_button);
		invite_button.setOnClickListener(this);
		group_img.setVisibility(View.VISIBLE);
		make_an_appointment = (Button) findViewById(R.id.make_an_appointment);
		make_an_appointment.setOnClickListener(this);
		has_make_an_appointment = (Button) findViewById(R.id.has_make_an_appointment);

		startProgressDialog();
		jsonData();

	}

	@Override
	public void onClick(View v) {

		Intent intent = new Intent();
		switch (v.getId()) {
		case R.id.btn_right:
			startProgressDialog();
			share();
			break;
		case R.id.message_board:
			intent.setClass(getApplicationContext(), GroupDiscussActivity.class);
			intent.putExtra("messageId", messageId);
			intent.putExtra("comments", mDataList);
			startActivityForResult(intent, AppConfig.REQUEST_GROUP_DISCUSS);
			break;
		case R.id.goin_group:
			intent.setClass(getApplicationContext(), ClubDetailActivity.class);
			intent.putExtra("sectionId", getGroupBean.getSectionId());
			startActivity(intent);
			break;
		case R.id.btn_left:
			ConfigCacheUtil.clearCache(null);
			finish();
			break;
		case R.id.btn_joined:
			startProgressDialog();

			checkSignin(messageId);
			break;
		case R.id.group_phone:
			CustomDialog.Builder customBuilder = new CustomDialog.Builder(GroupDetailActivity.this);
			ImageView img = new ImageView(GroupDetailActivity.this);
			img.setImageResource(R.drawable.ic_launcher);
			customBuilder.setImgIcon(img).setMessage("是否确认打电话?")

			.setPositiveButton("打电话", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					Intent call = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + group_phone.getText().toString())); // 创建一个意图
					GroupDetailActivity.this.startActivity(call);// 开始意图(及拨打电话)
					dialog.dismiss();

				}
			}).setNegativeButton("取消", new DialogInterface.OnClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which) {

					dialog.dismiss();

				}
			});
			customBuilder.create().show();

			break;
		case R.id.btn_joined_num:
			if ("0".equals(btn_joined_num.getText().toString().substring(0, 1))) {
				Alert.warn(this, "目前无人参加此次活动");

			} else {
				intent.setClass(getApplicationContext(), GroupJoinedActivity.class);
				intent.putExtra("JoinNum", String.valueOf(btn_joined_num.getText()));
				intent.putExtra("messageId", getGroupBean.getMessageId());
				intent.putExtra("group_name", getGroupBean.getTitle());
				intent.putExtra("group_img", getGroupBean.getLogo());
				startActivity(intent);
			}

			break;

		case R.id.btn_other_joined:
			intent.setClass(getApplicationContext(), ClubDetailActivity.class);
			intent.putExtra("sectionId", getGroupBean.getSectionId());
			startActivity(intent);
			break;
		case R.id.invite_button:
			intent.setClass(getApplicationContext(), ActivityAddFriends.class);
			intent.putExtra("choose_friends", true);
			intent.putExtra("messageId", getGroupBean.getMessageId());
			startActivity(intent);
			break;
		case R.id.check_all:
			intent.setClass(getApplicationContext(), NewHomeActivity.class);
			intent.putExtra("messageId", getGroupBean.getMessageId());
			intent.putExtra("group_name", getGroupBean.getTitle());
			startActivity(intent);
			break;
		case R.id.make_an_appointment:
			startProgressDialog();
			makeAnAppointment(getGroupBean.getMessageId());

			break;
		default:
			break;
		}

	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == RESULT_OK) {
			if (requestCode == AppConfig.REQUEST_GROUP_DISCUSS) {
				jsonData();
			} else if (requestCode == GOPAYMENT) {
				coin = data.getStringExtra("coin");
				rmb = data.getStringExtra("rmb");
				payCode = data.getStringExtra("payCode");
				startProgressDialog();
				signInJsonData(data.getStringExtra("messageId"));
			}
		}

	}

	@SuppressWarnings("unchecked")
	private void jsonData() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); //
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "getMessageNew1"));
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));// 添加要传递的参数
		params.add(new BasicNameValuePair("messageId", messageId));

		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {
				stopProgressDialog();
				main_linear.setVisibility(View.VISIBLE);
				String result = (String) object;

				Gson gson = new Gson();
				try {
					getGroupBean = gson.fromJson(result, GetGroupBean.class);
				} catch (Exception e) {
					return;
				}

				if (getGroupBean == null) {
					Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
					return;
				}
				// 字体加粗
				// 活动名称
				TextPaint tp = group_name.getPaint();
				tp.setFakeBoldText(true);
				group_name.setText(getGroupBean.getTitle());
				joinednum = Integer.parseInt(getGroupBean.getJoinCount());

				Type t = new TypeToken<List<Pictures>>() {
				}.getType();
				Gson g = new Gson();

				try {
					pictureList = g.fromJson(getGroupBean.getLogo(), t);
				} catch (Exception e) {
					return;
				}
				group_img.setAdapter(new ImagePagerAdapter(GroupDetailActivity.this, pictureList)
						.setInfiniteLoop(false));
				group_img.setOnPageChangeListener(new MyOnPageChangeListener());

				group_img.setInterval(2000);
				group_img.startAutoScroll();
				group_img.setCycle(true);
				group_img.setCurrentItem(Integer.MAX_VALUE / 2 - Integer.MAX_VALUE / 2 % ListUtils.getSize(pictureList));
				// 是group_img已经参加，或者过期
				if ("0".equals(getGroupBean.getJoinFlag())) {
					btn_joined.setVisibility(View.VISIBLE);
					btn_joined.setOnClickListener(GroupDetailActivity.this);
				} else if ("1".equals(getGroupBean.getJoinFlag())) {
					btn_joined.setVisibility(View.GONE);
					btn_cancle_joined.setVisibility(View.VISIBLE);
				} else if ("2".equals(getGroupBean.getJoinFlag())) {
					btn_joined.setVisibility(View.GONE);
					btn_cancle_joined.setVisibility(View.GONE);
					btn_other_joined.setVisibility(View.VISIBLE);
					btn_other_joined.setOnClickListener(GroupDetailActivity.this);
				} else if ("3".equals(getGroupBean.getJoinFlag())) {
					btn_joined.setVisibility(View.GONE);
					btn_cancle_joined.setVisibility(View.GONE);
					make_an_appointment.setVisibility(View.VISIBLE);
				} else if ("4".equals(getGroupBean.getJoinFlag())) {
					btn_joined.setVisibility(View.GONE);
					btn_cancle_joined.setVisibility(View.GONE);
					has_make_an_appointment.setVisibility(View.VISIBLE);
				}
				if ("0".equals(getGroupBean.getCanInvite())) {
					invite_button_unclick.setVisibility(View.VISIBLE);
					invite_button.setVisibility(View.GONE);
				} else {
					invite_button.setVisibility(View.VISIBLE);
					invite_button_unclick.setVisibility(View.GONE);
				}
				// 已经报名人数
				btn_joined_num.setText(getGroupBean.getJoinCount() + "人已抢到");
				// 活动描述
				group_describe.setText((getGroupBean.getContent()));
				group_time.setText("  " + getGroupBean.getTime());
				group_address.setText("  " + getGroupBean.getLocation());
				group_phone.setText("  " + getGroupBean.getPhone());
				// 主办方信息，图片和名字
				imageLoader.displayImage(AppConfig.HOST + getGroupBean.getSectionIcon(), club_img);
				goin_group_name.setText(getGroupBean.getSectionName());
				// 活动描述 活动规则 主办方简介
				group_theme.setText(getGroupBean.getPlatContent());
				group_describe.setText(getGroupBean.getContent());
				group_rules.setText(getGroupBean.getRule());
				// 判断是否有评论
				Type type = new TypeToken<List<Comments>>() {
				}.getType();
				Gson gson1 = new Gson();
				Object fromJson = gson1.fromJson(getGroupBean.getCommentArr(), type);
				ArrayList<Comments> mDataList = null;
				try {
					mDataList = (ArrayList<Comments>) fromJson;
				} catch (Exception e) {
					return;
				}
				if (null == mDataList) {
					mDataList = new ArrayList<Comments>();
				}
				if (mDataList.size() == 0) {
					message_title.setVisibility(View.GONE);
				} else {
					message_title.setVisibility(View.VISIBLE);
				}
				GroupDiscussListAdapter ListAdapter = new GroupDiscussListAdapter(GroupDetailActivity.this, mDataList);
				mMyListView.setAdapter(ListAdapter);
				mScrollView.scrollTo(0, 0);

			}

			@Override
			public void onFail(String exception) {

				stopProgressDialog();
				Alert.error(GroupDetailActivity.this, "与服务器连接失败，请检查网络");

			}

		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	/**
	 * 判断是否可以报名
	 *
	 * @param messageId
	 */
	@SuppressWarnings("unchecked")
	private void checkSignin(final String messageId) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); //
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "checkSigninNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("messageId", messageId));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {
				stopProgressDialog();
				String result = (String) object;
				Gson gson = new Gson();
				try {
					mGroupJoinBean = gson.fromJson(result, GroupJoinBean.class);
				} catch (Exception e) {
					return;
				}

				if ("0".equals(mGroupJoinBean.getResultCode())) {
					stopProgressDialog();
					Intent intent = new Intent(getApplicationContext(), GroupDetailPaymentActivity.class);
					intent.putExtra("messageId", messageId);
					startActivityForResult(intent, GOPAYMENT);

				} else {
					stopProgressDialog();
					Alert.error(GroupDetailActivity.this, mGroupJoinBean.getResultCode());
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(GroupDetailActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	/**
	 * 预约活动
	 *
	 * @param messageId
	 */
	@SuppressWarnings("unchecked")
	private void makeAnAppointment(final String messageId) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); //
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "orderActivityNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("messageId", messageId));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {
				stopProgressDialog();
				String result = (String) object;
				Gson gson = new Gson();
				try {
					mCloudBeansBean = gson.fromJson(result, CloudBeansBean.class);
				} catch (Exception e) {
					return;
				}

				if ("0".equals(mCloudBeansBean.getResultCode())) {
					Intent intent = new Intent();
					intent.putExtra("position", position);
					intent.putExtra("isOrder", true);
					setResult(RESULT_OK, intent);
					make_an_appointment.setVisibility(View.GONE);
					has_make_an_appointment.setVisibility(View.VISIBLE);
					Alert.info(GroupDetailActivity.this, "预约成功，请耐心等待活动开始");
				} else {
					stopProgressDialog();
					Alert.error(GroupDetailActivity.this, mCloudBeansBean.getResultCode());
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(GroupDetailActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	public class MyOnPageChangeListener implements OnPageChangeListener {

		@Override
		public void onPageSelected(int position) {
			// indexText.setText(new StringBuilder().append((position) %
			// ListUtils.getSize(imageUrlList) + 1).append("/")
			// .append(ListUtils.getSize(imageUrlList)));
		}

		@Override
		public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}

	/**
	 * 我要报名
	 *
	 * @param messageId
	 */
	@SuppressWarnings("unchecked")
	private void signInJsonData(String messageId) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); //
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "signinNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("messageId", messageId));
		params.add(new BasicNameValuePair("coin", TextUtils.isEmpty(coin) ? "0" : coin));
		params.add(new BasicNameValuePair("rmb", TextUtils.isEmpty(rmb) ? "0" : rmb));
		params.add(new BasicNameValuePair("payCode", TextUtils.isEmpty(payCode) ? "" : payCode));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {
				stopProgressDialog();
				String result = (String) object;
				Gson gson = new Gson();
				try {
					mCloudBeansBean = gson.fromJson(result, CloudBeansBean.class);
				} catch (Exception e) {
					return;
				}
				if ("0".equals(mCloudBeansBean.getResultCode())) {

					joinednum = joinednum + 1;
					if (joinednum > -1) {
						btn_joined_num.setText(joinednum + "人已抢到");
					}
					Intent intent = new Intent();
					intent.putExtra("position", position);
					intent.putExtra("isSigned", true);
					setResult(RESULT_OK, intent);
					stopProgressDialog();
					btn_joined.setVisibility(View.GONE);
					btn_cancle_joined.setVisibility(View.VISIBLE);
					btn_cancle_joined.setOnClickListener(GroupDetailActivity.this);
					if (!TextUtils.isEmpty(mCloudBeansBean.getCoinAlert())) {
						new PopupWindowAnimation(mainView, GroupDetailActivity.this);
					}
					ConfigCacheUtil.clearCache(null);
					Alert.info(GroupDetailActivity.this, "报名成功");
				} else {
					stopProgressDialog();
					Alert.info(GroupDetailActivity.this, result);
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(GroupDetailActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	/**
	 * 分享
	 *
	 * @param messageId
	 */
	@SuppressWarnings("unchecked")
	private void share() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); //
		// 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "shareNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("messageId", messageId));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;
				Gson gson = new Gson();
				try {
					mGroupShareBean = gson.fromJson(result, GroupShareBean.class);
				} catch (Exception e) {
					return;
				}
				if (mGroupShareBean != null) {
					showOnekeyshare(mGroupShareBean.getShareTitle(), mGroupShareBean.getShareContent(),
							mGroupShareBean.getLink(), mGroupShareBean.getPicUrl());
				} else {
					stopProgressDialog();
					Alert.info(GroupDetailActivity.this, result);
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(GroupDetailActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	public void showOnekeyshare(String shareTitle, String shareContent, String link, String picUrl) {
		OnekeyShare oks = new OnekeyShare();
		// 分享时Notification的图标和文字
		// oks.setNotification(R.drawable.ic_launcher,
		// this.getResources().getString(R.string.app_name));
		// // address是接收人地址，仅在信息和邮件使用
		// oks.setAddress("12345678901");
		// title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
		oks.setTitle(shareTitle);
		// // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
		// oks.setTitleUrl("http://sharesdk.cn");
		// text是分享文本，所有平台都需要这个字段
		oks.setText(shareContent);
		// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
		/* oks.setImagePath(MainActivity.TEST_IMAGE); */
		// imageUrl是图片的网络路径，新浪微博、人人网、QQ空间、
		// 微信的两个平台、Linked-In支持此字段
		oks.setImageUrl(AppConfig.HOST + picUrl);
		// url仅在微信（包括好s和朋友圈）中使用
		oks.setUrl(link);
		// appPath是待分享应用程序的本地路劲，仅在微信中使用
		// oks.setAppPath(MainActivity.TEST_IMAGE);
		// // comment是我对这条分享的评论，仅在人人网和QQ空间使用
		// oks.setComment(getContext().getString(R.string.share));
		// // site是分享此内容的网站名称，仅在QQ空间使用
		// oks.setSite(context.getString(R.string.app_name));
		// // siteUrl是分享此内容的网站地址，仅在QQ空间使用
		// oks.setSiteUrl("http://sharesdk.cn");
		// // venueName是分享社区名称，仅在Foursquare使用
		// oks.setVenueName("Southeast in China");
		// // venueDescription是分享社区描述，仅在Foursquare使用
		// oks.setVenueDescription("This is a beautiful place!");
		// // latitude是维度数据，仅在新浪微博、腾讯微博和Foursquare使用
		// oks.setLatitude(23.122619f);
		// // longitude是经度数据，仅在新浪微博、腾讯微博和Foursquare使用
		// oks.setLongitude(113.372338f);
		// // 是否直接分享（true则直接分享）
		// oks.setSilent(silent);
		// // 指定分享平台，和slient一起使用可以直接分享到指定的平台
		// if (platform != null) {
		// oks.setPlatform(platform);
		// }
		// 去除注释可通过OneKeyShareCallback来捕获快捷分享的处理结果
		// oks.setCallback(new OneKeyShareCallback());
		// 通过OneKeyShareCallback来修改不同平台分享的内容
		// oks.setCallback(new OneKeyShareCallback());
		oks.setCallback(new PlatformActionListener() {

			@Override
			public void onError(Platform arg0, int arg1, Throwable arg2) {
				// Alert.error(NewHomeActivity.this, "分享失败");

			}

			@Override
			public void onComplete(Platform arg0, int arg1, HashMap<String, Object> arg2) {
				shareSuccess();
			}

			@Override
			public void onCancel(Platform arg0, int arg1) {
				Alert.info(GroupDetailActivity.this, "分享取消");

			}

		});
		oks.show(this);
		stopProgressDialog();
	}

	/**
	 * 转发
	 * 
	 */
	@SuppressWarnings("unchecked")
	private void shareSuccess() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "shareSuccessNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("messageId", messageId));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				String result = (String) object;
				Gson gson = new Gson();
				try {
					mCloudBeansBean = gson.fromJson(result, CloudBeansBean.class);
				} catch (Exception e) {
					return;
				}
				if ("0".equals(mCloudBeansBean.getResultCode())) {
					if (!TextUtils.isEmpty(mCloudBeansBean.getCoinAlert())) {
						new PopupWindowAnimation(mainView, GroupDetailActivity.this);
					}
					Alert.info(GroupDetailActivity.this, "分享成功");
				} else {
					stopProgressDialog();
					Alert.error(GroupDetailActivity.this, result);
				}
			}

			@Override
			public void onFail(String exception) {
				stopProgressDialog();
				Alert.error(GroupDetailActivity.this, "与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	private void startProgressDialog() {
		if (progressDialog == null) {
			progressDialog = CustomProgressDialog.createDialog(this);
			progressDialog.setMessage("正在加载...");
		}

		progressDialog.show();
	}

	private void stopProgressDialog() {
		if (progressDialog != null) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}
}
